fn main() {
    println!("Hello, world!");
    // vec preclude的，不需要单独引入
    // 与tuple不同，Vec只能保存同类型的变量。
    // 变量本身分配在栈上。指向了堆内存。
    let mut v: Vec<i32> = Vec::new();
    let b: u32 =5;
    println!("addr of b is 0x{:X}", &b as *const u32 as usize);
    println!("addr of v is 0x{:X}", &v as *const Vec<i32> as usize);

    let a = vec![1, 2, 3];
    println!("a is {:?}", a);
    println!("a0 is {:p}", &a[0]);

    let c: [i32; 3] = [1, 2, 3];
    println!("c is {:?}", c);
    println!("c0 is 0x{:X}", &c[0] as *const i32 as usize);

    v.push(32);

    println!("v: {:?}", v);
    println!("v0: 0x{:X}", &v[0] as *const i32 as usize);

    // Move走
    let x = v[0];
    println!("v: {:?}", v);

    // get可以避免index out of range的异常。与Python的map一样。
    let does_not_exist = v.get(100);
    println!("100: {:?}", does_not_exist);

    // 迭代
    let mut v2 = vec![100, 20, 21];
    // 传递引用，i不会再进行复制。
    for i in &v2 {
        println!("v2: {}", i);
    }

    for i in &mut v2 {
        *i += 10;
    }
    println!("v2: {:?}", v2);
}
